/*
* @file gloabal_msg.cpp
* @brief Global message implementation file
* @author feiniao
* @version 1.0
* @date 2025-5-14
* @note This file contains the implementation of the Global_msg class
*       which is responsible for managing global messages and queues.
*/

#include "global_msg.h"

QueueHandle_t llm_output_queue = nullptr;                       // LLM output queue
QueueHandle_t stt_output_queue = nullptr;                       // STT output queue

/*
* @brief Initializes the LLM output queue
* @note This function creates a queue for LLM output messages.
* It uses FreeRTOS to create a queue with a maximum size of 3 and each item being a pointer to char.
* If the queue creation fails, it logs an error message.
*/
void Global_msg::init_llm_output_queue() {

    llm_output_queue = xQueueCreate(3, sizeof(char*));

    if (llm_output_queue == nullptr) {
        ESP_LOGE(TAG, "Failed to create LLM output queue");
    } else {
        ESP_LOGI(TAG, "LLM output queue created successfully");
    }
}


/*
* @brief Initializes the STT output queue
* @note This function creates a queue for STT output messages.
* It uses FreeRTOS to create a queue with a maximum size of 3 and each item being a pointer to char.
* If the queue creation fails, it logs an error message.
*/
void Global_msg::init_stt_output_queue() {

    stt_output_queue = xQueueCreate(3, sizeof(char*));
    
    if (stt_output_queue == nullptr) {
        ESP_LOGE(TAG, "Failed to create stt_output_queue");
    } else {
        ESP_LOGI(TAG, "stt_output_queue created successfully");
    }
}


/*
* @brief Constructor for the Global_msg class
* @note This function initializes the STT and LLM output queues.
* It also creates a mutex for task synchronization.
* The constructor is called when the Global_msg object is created.
*/
Global_msg::Global_msg() {

    init_stt_output_queue();
    init_llm_output_queue();
    ESP_LOGI(TAG, "Global_msg class created");
}


/*
* @brief Destructor for the Global_msg class
* @note This function is called when the Global_msg object is destroyed.
* It logs a message indicating that the class has been destroyed.
* The destructor is responsible for cleaning up any resources used by the class.
*/
Global_msg::~Global_msg() {
    ESP_LOGI(TAG, "Global_msg class destroyed");
}

